package com.rabbitmq.exchange.topic;

import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Connection;
import com.rabbitmq.client.ConnectionFactory;
import com.rabbitmq.utils.RabbitMQUtils;

import java.io.IOException;
import java.util.concurrent.TimeoutException;

public class Send {
    public static void main(String[] args) {
        //创建工厂对象用于指定链接的信息
        //创建链接以及通道,并添加异常处理同时在try..catch执行完成后自动释放资源
        try(Connection connection= RabbitMQUtils.getConnection();
            Channel channel=connection.createChannel()){
            String  exchangeName="topicExchange";
            channel.exchangeDeclare(exchangeName,"topic",true);
            String routingKey="aa.bb.cc";
            String message=String.format("Fanout测试消息  RoutingKey:  %s ",routingKey);
            channel.basicPublish(exchangeName,routingKey,null,message.getBytes());
            System.out.println("消息发送成功");
        } catch (TimeoutException | IOException e) {
            e.printStackTrace();
        }
    }
}
